package pmsjc.dpi.psaudavel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.ksoap2.serialization.SoapObject;

import pmsjc.dpi.locatend.classes.locatend;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class resultadopassoActivity extends Activity {
	
	//http://mobile.tutsplus.com/tutorials/android/android-sdk_table-layout/
	
	private static final String TAG = "resultadopassoActivity";
	private BuscaWS busca;
	private BuscaWS buscaResultado;
		
			
	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	      
	        criaTabela();
	 }
	  
	 @Override  
	    protected void onResume() {  
	        super.onResume();  
	        criaTabela(); 
	       }  
	 	 
	  
	/* public int contaIMC(){ 
	
		 int IMC = 0;
				 
		  buscaResultado = new BuscaWS();
		  List<stru_valor_imcrisco> arrayhistvalor= buscaResultado.CalculaRiscoIMCResult(PSaudavelActivity.pessoa.pessoa_cpf);
		    
		  for(stru_valor_imcrisco itemvalor : arrayhistvalor ){
			  
			  int peso = Integer.parseInt(itemvalor.psau_peso);
			  int altura = Integer.parseInt(itemvalor.psau_estatura);
			 			 		  
			  IMC = peso / (altura * altura);
			  
			  
			  int Fumo = Integer.parseInt(itemvalor.PSAU_TRCFUMO);
			  int IdadeSexo = Integer.parseInt(itemvalor.psau_trcsexoidade);
			  int PesoRisco = Integer.parseInt(itemvalor.psau_trcpeso);
			  int Atividade = Integer.parseInt(itemvalor.psau_trcatividfisica);
			  int Familia = Integer.parseInt(itemvalor.psau_trcantecedfamiliar);
			  int PA = Integer.parseInt(itemvalor.psau_trcpamaxima);
			  int Glicemia = Integer.parseInt(itemvalor.psau_trcglicemia);
			  int Colesterol = Integer.parseInt(itemvalor.psau_trccolesterol);
			  			  
			  //Risco = Fumo + IdadeSexo + PesoRisco + Atividade + Familia + PA + Glicemia + Colesterol;
			  
		  } // fecha o for(stru_valor_imcrisco item : arrayhistvalor ){
		 
		  return IMC;
		  
	 }*/
	 
	/* public int contaRisco(){ 
			
		 int Risco = 0;
		 
		  buscaResultado = new BuscaWS();
		  List<stru_valor_imcrisco> arrayhistvalor= buscaResultado.CalculaRiscoIMCResult(PSaudavelActivity.pessoa.pessoa_cpf);
		    
		  for(stru_valor_imcrisco itemvalor : arrayhistvalor ){
			 		  			  
			  int Fumo = Integer.parseInt(itemvalor.PSAU_TRCFUMO);
			  int IdadeSexo = Integer.parseInt(itemvalor.psau_trcsexoidade);
			  int PesoRisco = Integer.parseInt(itemvalor.psau_trcpeso);
			  int Atividade = Integer.parseInt(itemvalor.psau_trcatividfisica);
			  int Familia = Integer.parseInt(itemvalor.psau_trcantecedfamiliar);
			  int PA = Integer.parseInt(itemvalor.psau_trcpamaxima);
			  int Glicemia = Integer.parseInt(itemvalor.psau_trcglicemia);
			  int Colesterol = Integer.parseInt(itemvalor.psau_trccolesterol);
			  			  
			  Risco = Fumo + IdadeSexo + PesoRisco + Atividade + Familia + PA + Glicemia + Colesterol;
			  
		  } // fecha o for(stru_valor_imcrisco item : arrayhistvalor ){
		 
		  return Risco;
		  
	 }*/
	 
	 
	 public void criaTabela(){ 
	 
	       TableLayout table = new TableLayout(this);
	        
	       table.setStretchAllColumns(true);
	        table.setShrinkAllColumns(true);
	       
	        TableRow rowTitle = new TableRow(this);
	        rowTitle.setGravity(Gravity.CENTER_HORIZONTAL);
	        
	    	//*** Título ***// 
           	TextView title = new TextView(this);
		    title.setText("Resultado de Exames já realizados");
		    title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
		    title.setGravity(Gravity.CENTER);
		    title.setTypeface(Typeface.DEFAULT_BOLD);
		    TableRow.LayoutParams params = new TableRow.LayoutParams();
		    params.span = 11;
		    rowTitle.addView(title, params);
	       	        
	        // ***************************************** //
	     	 
	      	        
	       TableRow rowCabecalho = new TableRow(this);
	              
			    //*** Cabeçalho ***// 
			    TextView Data = new TextView(this);
			    TextView TIPO_EXAME = new TextView(this);
			    TextView Altura = new TextView(this);
			    TextView Peso = new TextView(this);			   			    
			    TextView IMC = new TextView(this);			    
			    TextView PRESSAO_ARTERIAL = new TextView(this);
			    TextView ABDOMEM = new TextView(this);
			    TextView GLICEMIA = new TextView(this);
			    TextView COLESTEROL = new TextView(this);
			    TextView FUMO = new TextView(this);
			    TextView ATIVIDADE_FISICA = new TextView(this);
			    TextView Risco = new TextView(this);
			   
			    Data.setText("DATA");
			    Data.setTypeface(Typeface.DEFAULT_BOLD); 
			    Data.setGravity(Gravity.CENTER);
			    
			    TIPO_EXAME.setText("TIPO EXAME");
			    TIPO_EXAME.setTypeface(Typeface.DEFAULT_BOLD);
			    TIPO_EXAME.setGravity(Gravity.CENTER);
			   
			    Altura.setText("ALTURA");
			    Altura.setTypeface(Typeface.DEFAULT_BOLD);
			    Altura.setGravity(Gravity.CENTER);
			    
			    Peso.setText("PESO");
			    Peso.setTypeface(Typeface.DEFAULT_BOLD);
			    Peso.setGravity(Gravity.CENTER);
			    			   
			    
			    IMC.setText("IMC");
			    IMC.setTypeface(Typeface.DEFAULT_BOLD);
			    IMC.setGravity(Gravity.CENTER);
			   			   			    
			    PRESSAO_ARTERIAL.setText("PRES.ART");
			    PRESSAO_ARTERIAL.setTypeface(Typeface.DEFAULT_BOLD);
			    PRESSAO_ARTERIAL.setGravity(Gravity.CENTER);
			   
			    ABDOMEM.setText("ABDOMEM");
			    ABDOMEM.setTypeface(Typeface.DEFAULT_BOLD);
			    ABDOMEM.setGravity(Gravity.CENTER);
			    
			    GLICEMIA.setText("GLIC.");
			    GLICEMIA.setTypeface(Typeface.DEFAULT_BOLD);
			    GLICEMIA.setGravity(Gravity.CENTER);
			    
			    COLESTEROL.setText("COLEST");
			    COLESTEROL.setTypeface(Typeface.DEFAULT_BOLD);
			    COLESTEROL.setGravity(Gravity.CENTER);
			    	   
			    
			    FUMO.setText("FUMO");
			    FUMO.setTypeface(Typeface.DEFAULT_BOLD);
			    FUMO.setGravity(Gravity.CENTER);
			    
			    ATIVIDADE_FISICA.setText("ATV.FIS");
			    ATIVIDADE_FISICA.setTypeface(Typeface.DEFAULT_BOLD);
			    ATIVIDADE_FISICA.setGravity(Gravity.CENTER);
			    
			    Risco.setText("RISCO");
			    Risco.setTypeface(Typeface.DEFAULT_BOLD);
			    Risco.setGravity(Gravity.CENTER);
			   				    
			    rowCabecalho.addView(Data);
			    rowCabecalho.addView(TIPO_EXAME);
			    rowCabecalho.addView(Altura);
			    rowCabecalho.addView(Peso);
			    rowCabecalho.addView(IMC);
			    rowCabecalho.addView(PRESSAO_ARTERIAL);
			    rowCabecalho.addView(ABDOMEM);
			    rowCabecalho.addView(GLICEMIA);
			    rowCabecalho.addView(COLESTEROL);
			    rowCabecalho.addView(FUMO);
			    rowCabecalho.addView(ATIVIDADE_FISICA);
			    rowCabecalho.addView(Risco);
			    
			    
			    // Atribui os canpos na Table Row
			    
			    table.addView(rowTitle);
			    table.addView(rowCabecalho);
			   // setContentView(table); // exibe a tabela
			    	
			   // if (DadosHistAlterados){		     		    
			   
			    
			    //*** Busca a Quantidade de Resultados para o CPF consultado ***//
			    busca = new BuscaWS();
			    String res = busca.ContaResultadoPasso(PSaudavelActivity.pessoa.pessoa_cpf);
			    Log.i("Quantidade de exames: ", res.toString());
			    
			    
			    //*** Faz a chamada para os RESULTADOS ***//
			    
			    buscaResultado = new BuscaWS();
			    List<stru_pessoa_hist> arrayhist= buscaResultado.BuscaResultadoPasso(PSaudavelActivity.pessoa.pessoa_cpf);
			    
			    if (res != ("0")){			    	
			    				    	 
			   // 	Log.i("Igual a : ", res.toString());
			    	
			    	//CRia a variável 
			    	int contaPasso = Integer.parseInt(res);		    	

			    	contaPasso = arrayhist.size();
			    	// **********
			    
			    	
			    //if (DadosHistAlterados){	
			    		 
			    	for(stru_pessoa_hist item : arrayhist ){//
		    			   System.out.println(item.achou);
		    			   
		    			   TableRow rowLinhas0  = new TableRow(this);	
		   	    		
				    		TextView lData0 = new TextView(this);
				    		TextView lTIPO_EXAME0 = new TextView(this);
				    		TextView lAltura0 = new TextView(this);
				    		TextView lPeso0 = new TextView(this);
						    TextView lIMC0 = new TextView(this);
						    TextView lPRESSAO_ARTERIAL0 = new TextView(this);
						    TextView lABDOMEM0 = new TextView(this);
						    TextView lGLICEMIA0 = new TextView(this);						    
						    TextView lCOLESTEROL0 = new TextView(this);
						    TextView lFUMO0 = new TextView(this);
						    TextView lATIVIDADE_FISICA0 = new TextView(this);
						    TextView lRisco0 = new TextView(this);
		
					    	 	lData0.setText(item.psau_data);
					    	 	lData0.setTypeface(Typeface.DEFAULT); 
					    	 	lData0.setGravity(Gravity.CENTER);
					    	 					    	 	 
							    lTIPO_EXAME0.setText(item.tppa_descricao);
							    lTIPO_EXAME0.setTypeface(Typeface.DEFAULT);
							    lTIPO_EXAME0.setGravity(Gravity.CENTER);
							   
							    lAltura0.setText(item.psau_estatura);
							    lAltura0.setTypeface(Typeface.DEFAULT);
							    lAltura0.setGravity(Gravity.CENTER);
							    
					    	 	lPeso0.setText(item.psau_peso);
							    lPeso0.setTypeface(Typeface.DEFAULT);
							    lPeso0.setGravity(Gravity.CENTER);
							    							    
							   							    
							    lIMC0.setText(item.valorIMC);
							    lIMC0.setTypeface(Typeface.DEFAULT);
							    lIMC0.setGravity(Gravity.CENTER);
							    
							    lPRESSAO_ARTERIAL0.setText(item.psau_pamaxima);
							    lPRESSAO_ARTERIAL0.setTypeface(Typeface.DEFAULT);
							    lPRESSAO_ARTERIAL0.setGravity(Gravity.CENTER);
							    
							    lABDOMEM0.setText(item.psau_abdomen);
							    lABDOMEM0.setTypeface(Typeface.DEFAULT);
							    lABDOMEM0.setGravity(Gravity.CENTER);
							    
							    lGLICEMIA0.setText(item.psau_glicemia);
							    lGLICEMIA0.setTypeface(Typeface.DEFAULT);
							    lGLICEMIA0.setGravity(Gravity.CENTER);
							   							    
							    lCOLESTEROL0.setText(item.psau_colesterol);
							    lCOLESTEROL0.setTypeface(Typeface.DEFAULT);
							    lCOLESTEROL0.setGravity(Gravity.CENTER);
							  							    
							    lFUMO0.setText(item.PSAU_TRCFUMO);
							    lFUMO0.setTypeface(Typeface.DEFAULT);
							    lFUMO0.setGravity(Gravity.CENTER);
							  							  				    				    
							    lATIVIDADE_FISICA0.setText(item.PSAU_TRCATIVIDFISICA);
							    lATIVIDADE_FISICA0.setTypeface(Typeface.DEFAULT);
							    lATIVIDADE_FISICA0.setGravity(Gravity.CENTER);
							    
							   // int RiscoX = Integer.parseInt(item.PSAU_TRCATIVIDFISICA) + Integer.parseInt(item.PSAU_TRCFUMO) ;
							    
							    lRisco0.setText(item.valorRisco);
							    lRisco0.setTypeface(Typeface.DEFAULT);
							    lRisco0.setGravity(Gravity.CENTER);
							    							    
							    rowLinhas0.addView(lData0);
							    rowLinhas0.addView(lTIPO_EXAME0);
							    rowLinhas0.addView(lAltura0);		
							    rowLinhas0.addView(lPeso0);
							   	rowLinhas0.addView(lIMC0);
							    rowLinhas0.addView(lPRESSAO_ARTERIAL0);
							    rowLinhas0.addView(lABDOMEM0);
							    rowLinhas0.addView(lGLICEMIA0);
							    rowLinhas0.addView(lCOLESTEROL0);
							    rowLinhas0.addView(lFUMO0);
							    rowLinhas0.addView(lATIVIDADE_FISICA0);
							    rowLinhas0.addView(lRisco0);
							    
							    
							 // Atribui os canpos na Table Row
							  table.addView(rowLinhas0);
		    			   
		    		}
			    		    
				      				      
				       
			    } else {
			    	//Log.i("ZERO: ", res.toString()); 
			       			       
			    }
			    
			    
			    // cria a linha com a legenda dos dados
			    
			    
			    
			    
			  //*** Título ***// 		    
			    
			    TableRow rowLegendaEsp = new TableRow(this);
	           	TextView legendaEsp = new TextView(this);
	           	legendaEsp.setText(" ");
	           	legendaEsp.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
	           	legendaEsp.setGravity(Gravity.CENTER);
	           	legendaEsp.setTypeface(Typeface.SERIF.DEFAULT_BOLD);
			    params.span = 11;
			    
			    TableRow rowLegendaT1 = new TableRow(this);
	           	TextView legendaT1 = new TextView(this);
	           	legendaT1.setText(" ");
	           	legendaT1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
	           	legendaT1.setGravity(Gravity.CENTER);
	           	legendaT1.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    			    
			    TableRow rowLegendaT2 = new TableRow(this);
	           	TextView legendaT2 = new TextView(this);
	           	legendaT2.setText("FUMO");
	           	legendaT2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT2.setGravity(Gravity.CENTER);
	           	legendaT2.setTypeface(Typeface.DEFAULT_BOLD);
			    params.span = 11;
			    
			    TableRow rowLegendaT3 = new TableRow(this);
	           	TextView legendaT3 = new TextView(this);
	           	legendaT3.setText("0 - NUNCA FUMOU");
	           	legendaT3.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT3.setGravity(Gravity.CENTER);
	           	legendaT3.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    
			    TableRow rowLegendaT4 = new TableRow(this);
	           	TextView legendaT4 = new TextView(this);
	           	legendaT4.setText("1 - EX-FUMANTE");
	           	legendaT4.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT4.setGravity(Gravity.CENTER);
	           	legendaT4.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    
			  TableRow rowLegendaT5 = new TableRow(this);
	           	TextView legendaT5 = new TextView(this);
	           	legendaT5.setText("2 - MENOS DE 10 CIGARROS POR DIA");
	           	legendaT5.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT5.setGravity(Gravity.CENTER);
	           	legendaT5.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    		   
			    
			    TableRow rowLegendaT6 = new TableRow(this);
	           	TextView legendaT6 = new TextView(this);
	           	legendaT6.setText("8 - DE 10 A 20 CIGARROS");
	           	legendaT6.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT6.setGravity(Gravity.CENTER);
	           	legendaT6.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    
			    TableRow rowLegendaT7 = new TableRow(this);
	           	TextView legendaT7 = new TextView(this);
	           	legendaT7.setText("9 - DE 21 A 30 CIGARROS");
	           	legendaT7.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT7.setGravity(Gravity.CENTER);
	           	legendaT7.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    
			    TableRow rowLegendaT8 = new TableRow(this);
	           	TextView legendaT8 = new TextView(this);
	           	legendaT8.setText("10 - DE 31 A 40 CIGARROS");
	           	legendaT8.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT8.setGravity(Gravity.CENTER);
	           	legendaT8.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    
			    
			    //
			    
			    TableRow rowLegendaT9 = new TableRow(this);
	           	TextView legendaT9 = new TextView(this);
	           	legendaT9.setText(" ");
	           	legendaT9.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT9.setGravity(Gravity.CENTER);
	           	legendaT9.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    			    
			    TableRow rowLegendaT10 = new TableRow(this);
	           	TextView legendaT10 = new TextView(this);
	           	legendaT10.setText("ATIVIDADE FÍSICA");
	           	legendaT10.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT10.setGravity(Gravity.CENTER);
	           	legendaT10.setTypeface(Typeface.DEFAULT_BOLD);
			    params.span = 11;
			    
			    
			    TableRow rowLegendaT11 = new TableRow(this);
	           	TextView legendaT11 = new TextView(this);
	           	legendaT11.setText("0 - ATIV. PROF. ESP. INT");
	           	legendaT11.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT11.setGravity(Gravity.CENTER);
	           	legendaT11.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    
			    TableRow rowLegendaT12 = new TableRow(this);
	           	TextView legendaT12 = new TextView(this);
	           	legendaT12.setText("1 - ATIV. PROF. ESP. MOD.");
	           	legendaT12.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT12.setGravity(Gravity.CENTER);
	           	legendaT12.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			   			    
			    TableRow rowLegendaT13 = new TableRow(this);
	           	TextView legendaT13 = new TextView(this);
	           	legendaT13.setText("2 - ATIV. PROF. ESP. LEVE.");
	           	legendaT13.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT13.setGravity(Gravity.CENTER);
	           	legendaT13.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    
			    TableRow rowLegendaT14 = new TableRow(this);
	           	TextView legendaT14 = new TextView(this);
	           	legendaT14.setText("3 - ATIV. PROF. SEND. ESP. MOD.");
	           	legendaT14.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT14.setGravity(Gravity.CENTER);
	           	legendaT14.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    
			    TableRow rowLegendaT15 = new TableRow(this);
	           	TextView legendaT15 = new TextView(this);
	           	legendaT15.setText("4 - ATIV. PROF. SEND. POUCO ESP.");
	           	legendaT15.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
	           	legendaT15.setGravity(Gravity.CENTER);
	           	legendaT15.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    
			    TableRow rowLegendaT16 = new TableRow(this);
	           	TextView legendaT16 = new TextView(this);
	           	legendaT16.setText("6 - INATIVIDADE FÍSICA");
	           	legendaT16.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10	);
	           	legendaT16.setGravity(Gravity.CENTER);
	           	legendaT16.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			    
			    /*TableRow rowLegenda = new TableRow(this);
			    TextView legenda = new TextView(this);
	           	legenda.setText("LEGENDA");
	           	legenda.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
	           	legenda.setGravity(Gravity.CENTER);
	           	legenda.setTypeface(Typeface.DEFAULT, Typeface.BOLD); 	           	
	           	params.span = 11;
	           	           	
			    
	        	TableRow rowLegendaT1 = new TableRow(this);
	           	TextView legendaT1 = new TextView(this);
	           	legendaT1.setText(" ");
	           	legendaT1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
	           	legendaT1.setGravity(Gravity.CENTER);
	           	legendaT1.setTypeface(Typeface.DEFAULT);
			    params.span = 11;
			   			   		    
			    
			    
			   TableRow rowLegendaT2 = new TableRow(this);
	           
			   TextView A = new TextView(this);
			    TextView B = new TextView(this);
			    TextView C = new TextView(this);
			    TextView D = new TextView(this);			    
			    TextView E = new TextView(this);			    
			    TextView F = new TextView(this);
			    TextView G = new TextView(this);
			    TextView H = new TextView(this);
			    TextView I = new TextView(this);
			    TextView J = new TextView(this);
			    TextView K = new TextView(this);
			    
			    A.setText(" ");
			    A.setTypeface(Typeface.DEFAULT_BOLD); 
			    A.setGravity(Gravity.CENTER);
			    
			    B.setText(" ");
			    B.setTypeface(Typeface.DEFAULT_BOLD); 
			    B.setGravity(Gravity.CENTER);
			    
			    C.setText("0 - NUNCA FUMOU");
			    C.setTypeface(Typeface.DEFAULT); 
			    C.setGravity(Gravity.CENTER);
			    C.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
			    
			    D.setText(" ");
			    D.setTypeface(Typeface.DEFAULT_BOLD); 
			    D.setGravity(Gravity.CENTER);
			    
			    E.setText(" ");
			    E.setTypeface(Typeface.DEFAULT_BOLD); 
			    E.setGravity(Gravity.CENTER);
			    
			    F.setText(" ");
			    F.setTypeface(Typeface.DEFAULT_BOLD); 
			    F.setGravity(Gravity.CENTER);
			    
			    G.setText("0 - ATIV.PROF.ESP.INT");
			    G.setTypeface(Typeface.DEFAULT); 
			    G.setGravity(Gravity.CENTER);
			    G.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
			    
			    H.setText(" ");
			    H.setTypeface(Typeface.DEFAULT_BOLD); 
			    H.setGravity(Gravity.CENTER);
			    
			    I.setText(" ");
			    I.setTypeface(Typeface.DEFAULT_BOLD); 
			    I.setGravity(Gravity.CENTER);
			    
			    J.setText(" ");
			    J.setTypeface(Typeface.DEFAULT_BOLD); 
			    J.setGravity(Gravity.CENTER);
			    
			    K.setText(" ");
			    K.setTypeface(Typeface.DEFAULT_BOLD); 
			    K.setGravity(Gravity.CENTER);
			    
			    rowLegendaT2.addView(A);
			    rowLegendaT2.addView(B);
			    rowLegendaT2.addView(C);
			    rowLegendaT2.addView(D);
			    rowLegendaT2.addView(E);
			    rowLegendaT2.addView(F);
			    rowLegendaT2.addView(G);			    
			    rowLegendaT2.addView(H);
			    rowLegendaT2.addView(I);
			    rowLegendaT2.addView(J);
			    rowLegendaT2.addView(K);
			   
			
			    
			    TableRow rowLegendaT3 = new TableRow(this);
		           
				   TextView A1 = new TextView(this);
				    TextView B1= new TextView(this);
				    TextView C1 = new TextView(this);
				    TextView D1 = new TextView(this);			    
				    TextView E1 = new TextView(this);			    
				    TextView F1 = new TextView(this);
				    TextView G1 = new TextView(this);
				    TextView H1 = new TextView(this);
				    TextView I1 = new TextView(this);
				    TextView J1 = new TextView(this);
				    TextView K1 = new TextView(this);
				    
				    A1.setText(" ");
				    A1.setTypeface(Typeface.DEFAULT_BOLD); 
				    A1.setGravity(Gravity.CENTER);
				    
				    B1.setText(" ");
				    B1.setTypeface(Typeface.DEFAULT_BOLD); 
				    B1.setGravity(Gravity.CENTER);
				    
				    C1.setText("FUMO");
				    C1.setTypeface(Typeface.DEFAULT_BOLD); 
				    C1.setGravity(Gravity.CENTER);
				    C1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
				    
				    D1.setText(" ");
				    D1.setTypeface(Typeface.DEFAULT_BOLD); 
				    D1.setGravity(Gravity.CENTER);
				    
				    E1.setText(" ");
				    E1.setTypeface(Typeface.DEFAULT_BOLD); 
				    E1.setGravity(Gravity.CENTER);
				    
				    F1.setText(" ");
				    F1.setTypeface(Typeface.DEFAULT_BOLD); 
				    F1.setGravity(Gravity.CENTER);
				    
				    G1.setText("ATV.FÍS");
				    G1.setTypeface(Typeface.DEFAULT_BOLD); 
				    G1.setGravity(Gravity.CENTER);
				    G1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
				    
				    H1.setText(" ");
				    H1.setTypeface(Typeface.DEFAULT_BOLD); 
				    H1.setGravity(Gravity.CENTER);
				    
				    I1.setText(" ");
				    I1.setTypeface(Typeface.DEFAULT_BOLD); 
				    I1.setGravity(Gravity.CENTER);
				    
				    J1.setText(" ");
				    J1.setTypeface(Typeface.DEFAULT_BOLD); 
				    J1.setGravity(Gravity.CENTER);
				    
				    K1.setText(" ");
				    K1.setTypeface(Typeface.DEFAULT_BOLD); 
				    K1.setGravity(Gravity.CENTER);
				    
				    rowLegendaT3.addView(A1);
				    rowLegendaT3.addView(B1);
				    rowLegendaT3.addView(C1);
				    rowLegendaT3.addView(D1);
				    rowLegendaT3.addView(E1);
				    rowLegendaT3.addView(F1);
				    rowLegendaT3.addView(G1);			    
				    rowLegendaT3.addView(H1);
				    rowLegendaT3.addView(I1);
				    rowLegendaT3.addView(J1);
				    rowLegendaT3.addView(K1);				    
				    
				    
				    
				    
				    TableRow rowLegendaT4 = new TableRow(this);
			           
					   TextView A3 = new TextView(this);
					    TextView B3 = new TextView(this);
					    TextView C3 = new TextView(this);
					    TextView D3 = new TextView(this);			    
					    TextView E3 = new TextView(this);			    
					    TextView F3 = new TextView(this);
					    TextView G3 = new TextView(this);
					    TextView H3 = new TextView(this);
					    TextView I3 = new TextView(this);
					    TextView J3 = new TextView(this);
					    TextView K3 = new TextView(this);
					    
					    A3.setText(" ");
					    A3.setTypeface(Typeface.DEFAULT_BOLD); 
					    A3.setGravity(Gravity.CENTER);
					    
					    B3.setText(" ");
					    B3.setTypeface(Typeface.DEFAULT_BOLD); 
					    B3.setGravity(Gravity.CENTER);
					    B3.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
					    
					    C3.setText("1 - EX-FUMANTE");
					    C3.setTypeface(Typeface.DEFAULT); 
					    C3.setGravity(Gravity.CENTER);
					    C3.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
					    
					    D3.setText(" ");
					    D3.setTypeface(Typeface.DEFAULT_BOLD); 
					    D3.setGravity(Gravity.CENTER);
					    
					    E3.setText(" ");
					    E3.setTypeface(Typeface.DEFAULT_BOLD); 
					    E3.setGravity(Gravity.CENTER);
					    
					    F3.setText(" ");
					    F3.setTypeface(Typeface.DEFAULT_BOLD); 
					    F3.setGravity(Gravity.CENTER);
					    
					    G3.setText("1 - ATIV.PROF.ESP.MOD");
					    G3.setTypeface(Typeface.DEFAULT); 
					    G3.setGravity(Gravity.CENTER);
					    G3.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
					    
					    H3.setText(" ");
					    H3.setTypeface(Typeface.DEFAULT_BOLD); 
					    H3.setGravity(Gravity.CENTER);
					    
					    I3.setText(" ");
					    I3.setTypeface(Typeface.DEFAULT_BOLD); 
					    I3.setGravity(Gravity.CENTER);
					    
					    J3.setText(" ");
					    J3.setTypeface(Typeface.DEFAULT_BOLD); 
					    J3.setGravity(Gravity.CENTER);
					    
					    K3.setText(" ");
					    K3.setTypeface(Typeface.DEFAULT_BOLD); 
					    K3.setGravity(Gravity.CENTER);
					    
					    rowLegendaT4.addView(A3);
					    rowLegendaT4.addView(B3);
					    rowLegendaT4.addView(C3);
					    rowLegendaT4.addView(D3);
					    rowLegendaT4.addView(E3);
					    rowLegendaT4.addView(F3);
					    rowLegendaT4.addView(G3);			    
					    rowLegendaT4.addView(H3);
					    rowLegendaT4.addView(I3);
					    rowLegendaT4.addView(J3);
					    rowLegendaT4.addView(K3);
			    
					  					    
					    TableRow rowLegendaT5 = new TableRow(this);
				           
						   TextView A5 = new TextView(this);
						    TextView B5 = new TextView(this);
						    TextView C5 = new TextView(this);
						    TextView D5 = new TextView(this);			    
						    TextView E5 = new TextView(this);			    
						    TextView F5 = new TextView(this);
						    TextView G5 = new TextView(this);
						    TextView H5 = new TextView(this);
						    TextView I5 = new TextView(this);
						    TextView J5 = new TextView(this);
						    TextView K5 = new TextView(this);
						    
						    A5.setText(" ");
						    A5.setTypeface(Typeface.DEFAULT_BOLD); 
						    A5.setGravity(Gravity.CENTER);
						    
						    B5.setText(" ");
						    B5.setTypeface(Typeface.DEFAULT_BOLD); 
						    B5.setGravity(Gravity.CENTER);
						    
						    C5.setText("2 - MENOS DE 10 CIGARROS");
						    C5.setTypeface(Typeface.DEFAULT); 
						    C5.setGravity(Gravity.CENTER);
						    C5.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
						    
						    D5.setText(" ");
						    D5.setTypeface(Typeface.DEFAULT_BOLD); 
						    D5.setGravity(Gravity.CENTER);
						    
						    E5.setText(" ");
						    E5.setTypeface(Typeface.DEFAULT_BOLD); 
						    E5.setGravity(Gravity.CENTER);
						    
						    F5.setText(" ");
						    F5.setTypeface(Typeface.DEFAULT_BOLD); 
						    F5.setGravity(Gravity.CENTER);
						    
						    G5.setText("2 - ATIV.PROF.ESP.LEVE");
						    G5.setTypeface(Typeface.DEFAULT); 
						    G5.setGravity(Gravity.CENTER);
						    G5.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
						    
						    H5.setText(" ");
						    H5.setTypeface(Typeface.DEFAULT_BOLD); 
						    H5.setGravity(Gravity.CENTER);
						    
						    I5.setText(" ");
						    I5.setTypeface(Typeface.DEFAULT_BOLD); 
						    I5.setGravity(Gravity.CENTER);
						    
						    J5.setText(" ");
						    J5.setTypeface(Typeface.DEFAULT_BOLD); 
						    J5.setGravity(Gravity.CENTER);
						    
						    K5.setText(" ");
						    K5.setTypeface(Typeface.DEFAULT_BOLD); 
						    K5.setGravity(Gravity.CENTER);
						    
						    rowLegendaT5.addView(A5);
						    rowLegendaT5.addView(B5);
						    rowLegendaT5.addView(C5);
						    rowLegendaT5.addView(D5);
						    rowLegendaT5.addView(E5);
						    rowLegendaT5.addView(F5);
						    rowLegendaT5.addView(G5);			    
						    rowLegendaT5.addView(H5);
						    rowLegendaT5.addView(I5);
						    rowLegendaT5.addView(J5);
						    rowLegendaT5.addView(K5);
						    
						    
						    TableRow rowLegendaT6 = new TableRow(this);
					           
							   TextView A6 = new TextView(this);
							    TextView B6 = new TextView(this);
							    TextView C6 = new TextView(this);
							    TextView D6 = new TextView(this);			    
							    TextView E6 = new TextView(this);			    
							    TextView F6 = new TextView(this);
							    TextView G6 = new TextView(this);
							    TextView H6 = new TextView(this);
							    TextView I6 = new TextView(this);
							    TextView J6 = new TextView(this);
							    TextView K6 = new TextView(this);
							    
							    A6.setText(" ");
							    A6.setTypeface(Typeface.DEFAULT_BOLD); 
							    A6.setGravity(Gravity.CENTER);
							    
							    B6.setText(" ");
							    B6.setTypeface(Typeface.DEFAULT_BOLD); 
							    B6.setGravity(Gravity.CENTER);
							    
							    C6.setText("8 - DE 10 A 20 CIGARROS");
							    C6.setTypeface(Typeface.DEFAULT); 
							    C6.setGravity(Gravity.CENTER);
							    C6.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
							    
							    D6.setText(" ");
							    D6.setTypeface(Typeface.DEFAULT_BOLD); 
							    D6.setGravity(Gravity.CENTER);
							    
							    E6.setText(" ");
							    E6.setTypeface(Typeface.DEFAULT_BOLD); 
							    E6.setGravity(Gravity.CENTER);
							    
							    F6.setText(" ");
							    F6.setTypeface(Typeface.DEFAULT_BOLD); 
							    F6.setGravity(Gravity.CENTER);
							    
							    G6.setText("3 - ATIV.PROF.SEND.ESP.MOD");
							    G6.setTypeface(Typeface.DEFAULT); 
							    G6.setGravity(Gravity.CENTER);
							    G6.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
							    
							    H6.setText(" ");
							    H6.setTypeface(Typeface.DEFAULT_BOLD); 
							    H6.setGravity(Gravity.CENTER);
							    
							    I6.setText(" ");
							    I6.setTypeface(Typeface.DEFAULT_BOLD); 
							    I6.setGravity(Gravity.CENTER);
							    
							    J6.setText(" ");
							    J6.setTypeface(Typeface.DEFAULT_BOLD); 
							    J6.setGravity(Gravity.CENTER);
							    
							    K6.setText(" ");
							    K6.setTypeface(Typeface.DEFAULT_BOLD); 
							    K6.setGravity(Gravity.CENTER);
							    
							    rowLegendaT6.addView(A6);
							    rowLegendaT6.addView(B6);
							    rowLegendaT6.addView(C6);
							    rowLegendaT6.addView(D6);
							    rowLegendaT6.addView(E6);
							    rowLegendaT6.addView(F6);
							    rowLegendaT6.addView(G6);			    
							    rowLegendaT6.addView(H6);
							    rowLegendaT6.addView(I6);
							    rowLegendaT6.addView(J6);
							    rowLegendaT6.addView(K6);
						    
						    
							    TableRow rowLegendaT7 = new TableRow(this);
						           
								   TextView A7 = new TextView(this);
								    TextView B7 = new TextView(this);
								    TextView C7 = new TextView(this);
								    TextView D7 = new TextView(this);			    
								    TextView E7 = new TextView(this);			    
								    TextView F7 = new TextView(this);
								    TextView G7 = new TextView(this);
								    TextView H7 = new TextView(this);
								    TextView I7 = new TextView(this);
								    TextView J7 = new TextView(this);
								    TextView K7 = new TextView(this);
								    
								    A7.setText(" ");
								    A7.setTypeface(Typeface.DEFAULT_BOLD); 
								    A7.setGravity(Gravity.CENTER);
								    
								    B7.setText(" ");
								    B7.setTypeface(Typeface.DEFAULT_BOLD); 
								    B7.setGravity(Gravity.CENTER);
								    
								    C7.setText("9 - DE 21 A 30 CIGARROS");
								    C7.setTypeface(Typeface.DEFAULT); 
								    C7.setGravity(Gravity.CENTER);
								    C7.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
								    
								    D7.setText(" ");
								    D7.setTypeface(Typeface.DEFAULT_BOLD); 
								    D7.setGravity(Gravity.CENTER);
								    
								    E7.setText(" ");
								    E7.setTypeface(Typeface.DEFAULT_BOLD); 
								    E7.setGravity(Gravity.CENTER);
								    
								    F7.setText(" ");
								    F7.setTypeface(Typeface.DEFAULT_BOLD); 
								    F7.setGravity(Gravity.CENTER);
								    
								    G7.setText("4 - ATIV.PROF.SEND.POUCO ESP");
								    G7.setTypeface(Typeface.DEFAULT); 
								    G7.setGravity(Gravity.CENTER);
								    G7.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
								    
								    H7.setText(" ");
								    H7.setTypeface(Typeface.DEFAULT_BOLD); 
								    H7.setGravity(Gravity.CENTER);
								    
								    I7.setText(" ");
								    I7.setTypeface(Typeface.DEFAULT_BOLD); 
								    I7.setGravity(Gravity.CENTER);
								    
								    J7.setText(" ");
								    J7.setTypeface(Typeface.DEFAULT_BOLD); 
								    J7.setGravity(Gravity.CENTER);
								    
								    K7.setText(" ");
								    K7.setTypeface(Typeface.DEFAULT_BOLD); 
								    K7.setGravity(Gravity.CENTER);
								    
								    rowLegendaT7.addView(A7);
								    rowLegendaT7.addView(B7);
								    rowLegendaT7.addView(C7);
								    rowLegendaT7.addView(D7);
								    rowLegendaT7.addView(E7);
								    rowLegendaT7.addView(F7);
								    rowLegendaT7.addView(G7);			    
								    rowLegendaT7.addView(H7);
								    rowLegendaT7.addView(I7);
								    rowLegendaT7.addView(J7);
								    rowLegendaT7.addView(K7);
								    
								    TableRow rowLegendaT8 = new TableRow(this);
							           
									   TextView A8 = new TextView(this);
									    TextView B8 = new TextView(this);
									    TextView C8 = new TextView(this);
									    TextView D8 = new TextView(this);			    
									    TextView E8 = new TextView(this);			    
									    TextView F8 = new TextView(this);
									    TextView G8 = new TextView(this);
									    TextView H8 = new TextView(this);
									    TextView I8 = new TextView(this);
									    TextView J8 = new TextView(this);
									    TextView K8 = new TextView(this);
									    
									    A8.setText(" ");
									    A8.setTypeface(Typeface.DEFAULT_BOLD); 
									    A8.setGravity(Gravity.CENTER);
									    
									    B8.setText(" ");
									    B8.setTypeface(Typeface.DEFAULT_BOLD); 
									    B8.setGravity(Gravity.CENTER);
									    
									    C8.setText("10 - DE 31 A 40 CIGARROS");
									    C8.setTypeface(Typeface.DEFAULT); 
									    C8.setGravity(Gravity.CENTER);
									    C8.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
									    
									    D8.setText(" ");
									    D8.setTypeface(Typeface.DEFAULT_BOLD); 
									    D8.setGravity(Gravity.CENTER);
									    
									    E8.setText(" ");
									    E8.setTypeface(Typeface.DEFAULT_BOLD); 
									    E8.setGravity(Gravity.CENTER);
									    
									    F8.setText(" ");
									    F8.setTypeface(Typeface.DEFAULT_BOLD); 
									    F8.setGravity(Gravity.CENTER);
									    
									    G8.setText("6 - INATIVIDADE FÍSICA");
									    G8.setTypeface(Typeface.DEFAULT); 
									    G8.setGravity(Gravity.CENTER);
									    G8.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
									    
									    H8.setText(" ");
									    H8.setTypeface(Typeface.DEFAULT_BOLD); 
									    H8.setGravity(Gravity.CENTER);
									    
									    I8.setText(" ");
									    I8.setTypeface(Typeface.DEFAULT_BOLD); 
									    I8.setGravity(Gravity.CENTER);
									    
									    J8.setText(" ");
									    J8.setTypeface(Typeface.DEFAULT_BOLD); 
									    J8.setGravity(Gravity.CENTER);
									    
									    K8.setText(" ");
									    K8.setTypeface(Typeface.DEFAULT_BOLD); 
									    K8.setGravity(Gravity.CENTER);
									    
									    rowLegendaT8.addView(A8);
									    rowLegendaT8.addView(B8);
									    rowLegendaT8.addView(C8);
									    rowLegendaT8.addView(D8);
									    rowLegendaT8.addView(E8);
									    rowLegendaT8.addView(F8);
									    rowLegendaT8.addView(G8);			    
									    rowLegendaT8.addView(H8);
									    rowLegendaT8.addView(I8);
									    rowLegendaT8.addView(J8);
									    rowLegendaT8.addView(K8);
							    
							    
							    
			    table.addView(legendaEsp);
			    table.addView(legenda);
			    table.addView(legendaT1);
			    table.addView(rowLegendaT3);
			    table.addView(rowLegendaT2);
			    table.addView(rowLegendaT4);
			    table.addView(rowLegendaT5);
			    table.addView(rowLegendaT6);
			    table.addView(rowLegendaT7);
			    table.addView(rowLegendaT8);*/
			  			    			    
			    //rowLegenda.addView(legenda, params);
			    
			    table.addView(legendaEsp);
			    table.addView(legendaT1);
			    table.addView(legendaT2);
			    table.addView(legendaT3);
			    table.addView(legendaT4);
			    table.addView(legendaT5);
			    table.addView(legendaT6);
			    table.addView(legendaT7);
			    table.addView(legendaT8);			    
			    table.addView(legendaT9);
			    table.addView(legendaT10);
			    table.addView(legendaT11);
			    table.addView(legendaT12);
			    table.addView(legendaT13);
			    table.addView(legendaT14);
			    table.addView(legendaT15);
			    table.addView(legendaT16);
			    
			    setContentView(table); // exibe a tabela 
			   		   
			   
	     }
 
}